import fetch from 'common/src/utils/fetch'
import UTILS from "common/src/utils/utils";
const SERVICE = '/api/textbookservice'
const TEACHING_CONTROLLER = 'teachingTextbook'
/**
 * 获取教材类型
 */
export function getTextBookType(data) {
    return fetch({
        url: '/api/textbookservice/textbookType/list',
        method: 'post',
        data
    })
}
/**
 * 增加教材信息
 * @param {*} data
 */
export function insertTextbook(data) {
    return fetch({
        url: '/api/textbookservice/textbook',
        method: 'post',
        data
    })
}
/**
 * 删除教材信息（包含批量删除）
 * @param {*} data
 */
export function delTextbookBatch(data) {
    return fetch({
        url: '/api/textbookservice/textbook',
        method: 'delete',
        data
    })
}
/**
 * 编辑教材信息
 * @param {*} data
 */
export function updateTextbookById(data) {
    return fetch({
        url: '/api/textbookservice/textbook',
        method: 'put',
        data
    })
}
/**
 * 提交教材信息
 * @param {*} data
 */
export function submit(data) {
    return fetch({
        url: '/api/textbookservice/textbook/submit',
        method: 'post',
        data
    })
}
/**
 * 根据id查询教材信息详情
 * @param {*} id
 */
export function findTextbookById(id) {
    return fetch({
        url: '/api/textbookservice/textbook/' + id
    })
}
/**
 * 根据条件，分页(不分页)查询
 * @param {*} data
 */
export function queryTextbookListByPage(data) {
    return fetch({
        url: `${SERVICE}/textbook/list`,
        method: 'post',
        data
    })
}
/**
 * 根据当前年份生成code
 */
export function autoCode() {
    return fetch({
        url: '/api/textbookservice/textbook/code'
    })
}
/**
 * 导出教材清单
 */
export function exportList(data) {
    return fetch({
        url: '/api/textbookservice/textbook/excel',
        method: 'post',
        showMask: false,
        data
    })
}
/**
 * 导出教师主编本专业教材情况
 */
export function exportMajor(grade) {
    return fetch({
        url: '/api/textbookservice/textbook/excel/' + grade,
        showMask: false
    })
}
/**
 * 下载模板
 */
export function downTemplate() {
    return '/api/textbookservice/textbook/template'
}
/**
 * 获取导入导师库api
 */
export function getImportUrl() {
    return '/api/textbookservice/textbook/import'
}

/**
 * 列表界面根据id提交
 */
export function submitById(data) {
    return fetch({
        url: '/api/textbookservice/textbook/submit/' + data,
        method: 'post'
    })
}

/**
 * 增加教学班教材信息
 * @param {*} data
 */
export function insertTeachingTextbook(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}`,
        method: 'post',
        data
    })
}
/**
 * 根据教学班id查询教学班教材详情
 * @param {*} classId
 */
export function findTeachingTextbookById(classId) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/${classId}`,
        method: 'get'
    })
}
/**
 * 变更教学班教材设置
 * @param {*} data
 */
export function updateTeachingTextbookById(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}`,
        method: 'put',
        data
    })
}
/**
 * 教学班教材发布
 * @param {*} data
 */
export function publish(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/publish`,
        method: 'post',
        data
    })
}
/**
 * 下载教学班教材模板
 */
export function downTeachingTemplate() {
    return `${SERVICE}/${TEACHING_CONTROLLER}/template`
}

/**
 * 导入教学班教材模板
 */
export const importTeaching = `${SERVICE}/${TEACHING_CONTROLLER}/import`

/**
 * 导出开课情况
 * @param {*} data
 */
export function exportOpenClass(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/excel/open`,
        method: 'post',
        showMask: false,
        data
    })
}
/**
 * 导出教学班教材清单
 * @param {*} data
 */
export function exportTeachingList(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/excel`,
        method: 'post',
        showMask: false,
        data
    })
}
/**
 * 导出课程教材汇总表
 * @param {*} calendarId
 */
export function exportCourseList(calendarId) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/excel/count/${calendarId}`,
        method: 'post',
        showMask: false
    })
}
/**
 * 批量指定
 * @param {*} data
 */
export function assignBatch(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/batch`,
        method: 'post',
        showMask: false,
        data
    })
}
/**
 * 权限校验
 * @param {*} data
 */
export function checkAuth(classId) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/check/` + classId
    })
}

export function updateNecessaryField(data) {
    return fetch({
        url: '/api/textbookservice/textbook/updateNecessaryField',
        method: 'post',
        data
    })
}

export function repeal(data) {
    return fetch({
        url: '/api/textbookservice/textbook/repeal',
        method: 'post',
        data
    })
}

export function teachingRepeal(data) {
    return fetch({
        url: `${SERVICE}/${TEACHING_CONTROLLER}/repeal`,
        method: 'post',
        data
    })
}

export function getTextBookTraining(data) {
    return fetch({
        url: `${SERVICE}/textbook/getTextBookTraining`,
        method: 'post',
        data
    })
}
//获取所有学院部门
export function findAllDeptList(manageDept) {
    return fetch({
        url: '/api/userservice/dept/findDept?virtualDept=0&&manageDept=' + manageDept,
        method: 'get'
    })
}

/**
 * 导出教材PDF
 * @param data
 */
export function exportPdf(data) {
    return fetch({
        url: '/api/textbookservice/teachingTextbook/exportPdf',
        method: 'post',
        data,
        showMask: false
    })
}

export function getResultByKey(key) {
    return fetch({
        url: `/api/textbookservice/teachingTextbook/getExportResult/${key}`,
        method: 'get',
        showMask: false
    })
}

export function doDownload(path, fileName) {
    return fetch({
        url: `/api/commonservice/obsfile/downloadfile?objectkey=${path}`,
        method: 'get',
        responseType: "blob",
        timeout: 0
    }).then(res => {
        UTILS.downloadFile(
            res,
            fileName,
            fileName.substr(fileName.lastIndexOf(".") + 1)
        );
    });
};

//教学班教材信息管理-教材登记清单、马工程教材清单、已发教材清单、境外教材清单列表导出
export function orderExport(data) {
    return fetch({
        url: '/api/textbookservice/teachingTextbook/orderExport',
        method: 'post',
        data,
        showMask: false
    })
}

export function exportListByType(data) {
    return fetch({
        url: '/api/textbookservice/teachingTextbook/export',
        method: 'post',
        data,
        showMask: false
    })
}

export function exportBooks(data) {
    return fetch({
        url: '/api/textbookservice/textbook/exportPdf',
        method: 'post',
        data,
        showMask: false
    })
}
export function getAllManagers(data) {
    return fetch({
        url: '/api/textbookservice/textbookManager',
        method: 'get'
    })
}
export function saveBookNoFlow(data) {
    return fetch({
        url: '/api/textbookservice/textbook/updateNotFlowTextbook',
        method: 'post',
        data
    })
}
